package com.qfedu.service.impl;

import com.qfedu.dao.DepartDao;
import com.qfedu.entity.GroupDepartData;
import com.qfedu.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class DepartServiceImpl implements DepartService {

    @Autowired
    private DepartDao departDao;

    @Override
    public GroupDepartData getCountByDepart() {

        List<Map>  mapList = departDao.getCountByDepart();


        List<String> departList = new ArrayList<>();
        List<Integer> departNumList = new ArrayList<>();

        for (Map map:mapList){
            // key  部门名称
            departList.add((String) map.get("name"));

            // 获取每个部门的 数量
            Long num = (Long) map.get("num");
            departNumList.add(num.intValue());
        }

        GroupDepartData groupDepartData = new GroupDepartData();
        //部门名称列表
        groupDepartData.setDepartList(departList);
        // 部门人数
        groupDepartData.setDepartNumList(departNumList);

        return groupDepartData;
    }
}
